package com.iscreen.utils.strings;

import java.util.Iterator;
import java.util.List;

public class StringUtils
{
	public static String listToString(List<String> list,String delimiter)
	{
		StringBuilder builder = new StringBuilder();
		for (Iterator<String> iterator = list.iterator(); iterator.hasNext();)
		{
			String s = (String) iterator.next();
			builder.append(s);
			if (iterator.hasNext())
			{
				builder.append(delimiter);
			}
		}
		return builder.toString();
	}
	public static String trimDelimiter(String s, String delimiter)
	{
		String s1 = s.trim();
		if (s1.endsWith(delimiter))
		{
			return s1.substring(0,s1.length() - delimiter.length());
		}
		return s1;
	}
	public static boolean parseYesNoString(String s)
	{
		return parseYesNoString(s, false);
	}

	public static boolean parseYesNoString(String s, boolean defaultValue)
	{
		if (s == null || s.length() == 0)
		{
			return defaultValue;
		}
		else if (s.equalsIgnoreCase("Y") || s.equalsIgnoreCase("YES"))
		{
			return true;
		}
		else if (s.equalsIgnoreCase("N") || s.equalsIgnoreCase("NO"))
		{
			return false;
		}
		else
		{
			return defaultValue;
		}
	}
	
}
